

#include "nrf_drv_spi.h"

#define PAGE_NUM 2048
#define PAGE_SIZE 256
#define SPI_CS_PIN   24  /**< SPI CS Pin.*/
#define SPI_INSTANCE  0 /**< SPI instance index. */

static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
static volatile bool spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */
#define READ_STATUS 0xd7
#define READ_FLASH_ID 0x9f
#define MEMORY_PAGE_READ 0xd2
#define BUFFER_1_WRITE 0x84
#define BUFFER_1_READ 0xd4
#define BUFFER_1_TO_MEMORY_WITH_ERASE 0x83
#define MEMORY_PAGE_WRITE_THROUGH_BUFFER_1 0x82

void spi_event_handler(nrf_drv_spi_evt_t const * p_event);
void start_spi_xfer(uint32_t ss_pin);
void stop_spi_xfer(uint32_t ss_pin);
uint8_t at45db_read_status(const nrf_drv_spi_t *spi);
uint32_t at45db_read_flash_id(const nrf_drv_spi_t *spi);
void at45db_read_buffer1(const nrf_drv_spi_t *spi);
void at45db_write_buffer1(const nrf_drv_spi_t *spi);
void at45db_erase_chip(const nrf_drv_spi_t *spi);

void at45db_memory_page_write_through_buffer1(const nrf_drv_spi_t *spi,
                                                int32_t page_id,
                                                uint8_t *dat, uint32_t len);
void at45db_memory_page_read(const nrf_drv_spi_t *spi,
                                int32_t page_id,
                                uint8_t *dat, uint32_t len);


uint32_t at45db_spi_init(const nrf_drv_spi_t *spi);
void at45db_init();

